//
//  ZZHudView.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/17.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZZHudView.h"
#import "ZZMusicListGroup.h"
#import "ZZHudCell.h"
#import "ZZMusicList.h"
#import "MusicTool.h"
#import "ZZMusicModel.h"
#import "ZZDeviceModel.h"
#import "ZZDeviceManager.h"
#import "ZZDeviceGroup.h"
#import "DeviceTool.h"
#define kHudTableViewIdentifier @"HudTableViewIdentifier"
@interface ZZHudView()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UILabel *selectLabel;

@property (weak, nonatomic) IBOutlet UILabel *sectionLabel;

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end


@implementation ZZHudView

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZZHudCell" bundle:nil] forCellReuseIdentifier:kHudTableViewIdentifier];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    self.tableView.backgroundColor = [UIColor clearColor];
}

- (IBAction)removeBtnClick:(UIButton *)sender {
    
    [self removeFromSuperview];
}


#pragma mark - tableView Deleget & DataSoure

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (self.listGroup != nil) {
        
        return self.listGroup.listgroup.count;
    }
    
    if (self.deviceGroup != nil) {
        
        return self.deviceGroup.listDevice.count;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZZHudCell *cell = [tableView dequeueReusableCellWithIdentifier:kHudTableViewIdentifier];
    if (self.listGroup != nil) {
        
         cell.titleLabel.text = [self.listGroup.listgroup[indexPath.row] listName];
    } else {
        
        cell.titleLabel.text = [self.deviceGroup.listDevice[indexPath.row] listName];
    }
   
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.btnClick = ^{
      
        if (self.deviceModel != nil) {
            
            [[DeviceTool new] moveModel:self.deviceModel fromList:self.deviceList toList:self.deviceGroup.listDevice[indexPath.row]];
        } else {
            
              [[MusicTool new] moveModel:self.musicModel fromList:self.listMusic toList:self.listGroup.listgroup[indexPath.row]];
        }
      
        if (self.moveCommit) {
            
            self.moveCommit();
        }
        [self removeFromSuperview];
        
    };
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    

//
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    return 44;
}


#pragma mark - set & get
- (void)setMusicModel:(ZZMusicModel *)musicModel {
    
    _musicModel = musicModel;
    
    self.selectLabel.text = musicModel.musicName;
}

- (void)setDeviceModel:(ZZDeviceModel *)deviceModel {
    
    _deviceModel = deviceModel;
    self.selectLabel.text = deviceModel.deviceName;
}

- (void)setDeviceGroup:(ZZDeviceGroup *)deviceGroup {
    
    _deviceGroup = deviceGroup;
    [self.tableView reloadData];
}

- (void)setListGroup:(ZZMusicListGroup *)listGroup {
    
    _listGroup = listGroup;
    [self.tableView reloadData];
}



@end

